#ifndef _SEU_DISKIO_H_
#define _SEU_DISKIO_H_
#include"include.h"

typedef struct {
   int should_run;
   sem_t runLock;
   list_t *writeTasks;
   list_t *readTasks;
   sem_t work;
} filemanage_t;


filemanage_t *filemanageInit();
void filemanageWriteData(filemanage_t * manager,char *filename,
      long offset, void *data, int datalen);

/* Marks that there needs to be a data read at some point in the future. When
 * the read occurs, the callback function is called, callbacks are of the form
 * void func(void *data, int datalen, void *cookie, int error)
 */
void filemanageReadData(filemanage_t * manager, char *filename, long offset,
      int datalen, void *cookie, void (*callback) (void *, int, void *, int));

/* Runs the filemanager thread. This thread awaits tasks on the writeTasks
 * queue, and then consumes them by writing to disk.
 */
void filemanageRun(filemanage_t *manager);

/* Cleans up all memory a filemanage_t has allocated, allowing the thread
 * to come to an end safely
 */
void filemanageExitAndCleanup(filemanage_t *manager);

/* Essentially implements the bash command "mkdir -p dirs"
 */
void makeDirectoryTree(char *dirs);

#endif
